<template>
	<view class="down-box">
		<view class="wrap">
			<!-- <u-swiper :list="list" height="300"></u-swiper> -->
			<image class="ad-img" :src="adImg" @click="openAd" mode="scaleToFill"></image>
		</view>
		<view class="down-info">
			<view>当前设备：1234567810</view>
			<view>设备地址：福州市台江区中亭街</view>
			<view>其他信息</view>
			<view>其他信息</view>
		</view>
		<view type="primary" @click="tackDown" class="button-box">掉水</view>

		<u-toast ref="uToast" />
	</view>
</template>

<script>
	export default {
		data() {
			return {
				adImg:'/static/ad/weile.png',
				list: [{
						image: 'https://cdn.uviewui.com/uview/swiper/1.jpg',
						title: '昨夜星辰昨夜风，画楼西畔桂堂东'
					},
					{
						image: 'https://cdn.uviewui.com/uview/swiper/2.jpg',
						title: '身无彩凤双飞翼，心有灵犀一点通'
					},
					{
						image: 'https://cdn.uviewui.com/uview/swiper/3.jpg',
						title: '谁念西风独自凉，萧萧黄叶闭疏窗，沉思往事立残阳'
					}
				],
				deviceNo: '',
			}
		},
		methods: {
			openAd() {
				uni.navigateTo({
					url: '/pages/ad/weile'
				})
				// window.open('https://biaodan100.com/web/formview/619c401275a03c479478c31d')
			},
			tackDown() {
				
				const user = uni.getStorageSync('user')
				// this.$refs.uToast.show({
				// 	title: user + '111',
				// 	type: 'error',
				// })
				uni.request({
					url: 'https://dnk998877.top/device/open', // 请求路径
					method: 'POST', //请求方式
					data: {
						deviceNo: this.deviceNo,
						userId: user || ''
					},
					success: result => {
						//响应成功
						console.log(result)
						if (result.data.code === 200) {
							// this.$refs.uToast.show({
							// 	title: '掉水成功',
							// 	type: 'success',
							// })
							uni.redirectTo({
								url: '/pages/news/downSucess'
							})

						} else {
							this.$refs.uToast.show({
								title: result.data.msg,
								type: 'error',
							})
						}

						this.show = false
					},
					fail: err => {
						console.log(err);
						this.$refs.uToast.show({
							title: '掉水失败',
							type: 'error',
						})
						this.show = false
					} //失败
				})


			},
			/**
			 * 获取URL中某个字符串字段
			 * gup('id', 'https://www.lubanso.com/wx/home/?id=bHViYW5zb7W7DJI=&jhkfdhkjfda')
			 * //===> bHViYW5zb7W7DJI=
			 */
			GetRequest(urlStr) {
				if (typeof urlStr == "undefined") {
					var url = decodeURI(location.search); //获取url中"?"符后的字符串
				} else {
					var url = "?" + urlStr.split("?")[1];
				}
				var theRequest = new Object();
				if (url.indexOf("?") != -1) {
					let str = url.substr(1);
					let strs = str.split("&");
					for (var i = 0; i < strs.length; i++) {
						theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]);
					}
				}
				return theRequest;
			},
		},
		onLoad(option) {
			console.log(option);
			this.deviceNo = option.deviceNo
			// this.$refs.uToast.show({
			// 	title: '2222',
			// 	type: 'error',
			// })
			let test = decodeURIComponent(option.q)
			// this.$refs.uToast.show({
			// 	title: test,
			// 	type: 'error',
			// })
			if(option.q) {
				let test = decodeURIComponent(option.q)
				const resultObj = this.GetRequest(test);
				this.deviceNo = resultObj.deviceNo
			}
		},
	}
</script>

<style>
	.down-box {
		background-color: #edf5f3;
		width: 100vw;
		height: 100vh;
		padding: 0;
	}

	.wrap {
		padding: 40rpx 20rpx;
	}
	.ad-img {
		width: 700rpx;
		height: 300rpx;
	}
	.down-info {
		width: 95vw;
		height: 300rpx;
		background-color: #FFF;
		border-radius: 50rpx;
		margin-left: 2.5vw;
		padding: 20rpx;
		font-size: 32rpx;
		display: flex;
		flex-direction: column;
		justify-content: space-around;

	}

	.button-box {
		width: 100%;
		height: 80rpx;
		color: #FFF;
		line-height: 80rpx;
		text-align: center;
		/* background-color: #19BE6B; */

		background: linear-gradient(to right, #185ADB 0%, #39A2DB 100%);
		margin-top: 40rpx;
		border-radius: 20rpx;
		font-weight: 400;
	}
</style>
